package com.gemme.gemme.login;

import android.Manifest;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import com.gemme.gemme.BaseActivity;
import com.gemme.gemme.MainActivity;
import com.gemme.gemme.R;
import com.gemme.gemme.test.TestActivity;
import com.gemme.gemme.util.DpUtil;
import com.gemme.gemme.util.SPUtil;
import com.gemme.gemme.util.ShapeUtil;
import com.gemme.gemme.view.LoginView;
import com.gemme.gemme.view.MyButton;
import com.gemme.gemme.view.SanfangLoginUtil;
import com.jaeger.library.StatusBarUtil;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
/*
* 首次登录成功进入个人资料
* */
public class LoginNewActivity extends BaseActivity {
   Context context =  LoginNewActivity.this;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login_new);
        StatusBarUtil.setTransparent(this);
        initView();
//        judge();

        requestPemission();
    }

    private void initView() {
        MyButton bt_weixin_login = findViewById(R.id.bt_weixin_login);
        bt_weixin_login.setSatate(true);
        Button bt_tel_login = findViewById(R.id.bt_tel_login);

        ImageView iv_close = findViewById(R.id.iv_close);
        bt_tel_login.setBackground(ShapeUtil.setCornBgStrok(DpUtil.dp2px((Activity) context, 4),"#ffffffff",
                DpUtil.dp2px((Activity) context, 1),"#ff9D2C2F"));

        bt_weixin_login.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
//                startActivity(new Intent(context,WeixinLoginActivity.class));
                SanfangLoginUtil.createWeinDialog(context);
            }
        });

        bt_tel_login.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(context,TelLoginActivity.class));
                finish();
            }
        });
        iv_close.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(context,MainActivity.class));
                finish();
            }
        });

        findViewById(R.id.app_icon).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
//                startActivity(new Intent(context, TestActivity.class));
            }
        });
    }

    private void requestPemission() {
        if(Build.VERSION.SDK_INT>=23){
            String[] mPermissionList = new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE,Manifest.permission.ACCESS_FINE_LOCATION,Manifest.permission.CALL_PHONE,Manifest.permission.READ_LOGS,Manifest.permission.READ_PHONE_STATE, Manifest.permission.READ_EXTERNAL_STORAGE,Manifest.permission.SET_DEBUG_APP,Manifest.permission.SYSTEM_ALERT_WINDOW,Manifest.permission.GET_ACCOUNTS,Manifest.permission.WRITE_APN_SETTINGS};
            ActivityCompat.requestPermissions(this,mPermissionList,123);
        }
    }



    private void judge() {
        SharedPreferences MSP = getSharedPreferences(Constant.MSP, Context.MODE_PRIVATE);
         String access_token = MSP.getString(Constant.ACCESS_TOKEN, "").trim();

        if(!TextUtils.isEmpty(access_token)){
            startActivity(new Intent(context, MainActivity.class));
            finish();
        }
    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

    }
}